import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Vector;


public class SocketThreadForArrayOfChanges extends Thread {
        
        String hostName;
        int portNumber;
        Socket connectionToReceiver;
        Vector<PointDrawn> Changes;
        String UniqueStringofTabChanged;
        
        public SocketThreadForArrayOfChanges(String hostName, int portNumber, String StringofTabChanged, Vector<PointDrawn> Changes) {
                this.hostName = hostName;
                this.portNumber = portNumber;
                this.Changes = Changes;
                this.UniqueStringofTabChanged = StringofTabChanged;
        }
        
        public void run() {
                try {
                        connectionToReceiver = new Socket(hostName, portNumber);
                        if(connectionToReceiver == null) return;
                        DataOutputStream dos = new DataOutputStream(connectionToReceiver.getOutputStream());
                        dos.writeInt(3);
                        dos.writeUTF(UniqueStringofTabChanged);
                        //Going to change this to a unique string that gets
                        //changed
                        dos.writeInt(Changes.size());
                        
                        for(int c = 0; c < Changes.size(); c++) {
                                PointDrawn CurChange = Changes.get(c);
                                dos.writeInt(CurChange.x1);
                                dos.writeInt(CurChange.y1);
                                dos.writeInt(CurChange.radius);
                                dos.writeInt(CurChange.clr.getRGB());
                                int FakeBool;
                                if(CurChange.draw) {
                                        FakeBool = 1;
                                } else {
                                        FakeBool = 2;
                                }
                                dos.writeInt(FakeBool);
                                
                                if(c == Changes.size()-1) {
                                        System.out.println("xyr  "  + CurChange.x1 + "  "+ CurChange.y1 + "  "+ CurChange.radius); 
                                }
                        }
                        connectionToReceiver.close();
                } catch (UnknownHostException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                
        }
}
